package FlyweightOne;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FlyweightFactory {
	private Map<Character, Flyweight> map = new HashMap<Character, Flyweight>();
	
	/*
	 * 单纯享元工厂方法
	 */
	public Flyweight factory(Character state) {
		Flyweight fly = map.get(state);
		if (fly == null) {
			fly = new ConcreteFlyweight(state);
			map.put(state, fly);
		}
		return fly;
	}
	
	/*
	 * 复合享元工厂模式
	 */
	public Flyweight factory(List<Character> list) {
		ConcreteCompositeFlyweight fly = new ConcreteCompositeFlyweight();
		for (Character ch : list) {
			fly.add(ch, this.factory(ch));
		}
		return fly;
	}
}
